// import { DynamicComponentBase } from '../../../dynamic-model/dynamic/dynamic.component';
import { Component, Injector, AfterViewInit, ViewChild, ComponentFactoryResolver, Input, OnInit, OnChanges, SimpleChanges, ElementRef } from '@angular/core';

import * as echarts from 'echarts';
declare var document: any;

// import { ComponentsService } from '@app/shared/common/components/components.service';

@Component({
    selector: 'echarts',
    template: `<div [id]="id?id:data.id" #eleref style="height:300px;"></div>`
})
export class EChartComponent implements AfterViewInit, OnChanges {

    @Input('data') data: any;
    @Input('id') id: string;
    @Input('list') list: any;

    @ViewChild('eleref') eleref: ElementRef;

    chart: echarts.ECharts;

    constructor(
        // private _ComponentsService: ComponentsService
    ) {}

    ngOnInit() {
    }
    ngAfterViewInit(): void {
    }

    ngOnChanges(changes: SimpleChanges): void {
        if(this.list){
            this.init();
        }

    }

    init() {
        let self = this;
        self.chart = echarts.init(self.eleref.nativeElement,);
        self.chart.setOption(self.list);

        window.onresize = function(){
            self.chart.resize();
        }
    }
}